<template>
  <div class="mod-config editViewContainer">
    <table-view ref="view"
                :searchAttrs="searchAttrs"
                :primaryKey="primaryKey"
                :listApiName="listApiName"
                :deleteApiName="deleteApiName"
                :exportApiName="exportApiName"
                :showAttrs="showAttrs"
                :sumInfo='sumInfo'
                :optionWidth="200"
                :importApiName="importApiName"
                :adviceNoteFunc="adviceNoteFunc"
                :reorderFunc="reorderFunc"
    >
      <template v-slot:foot="{scope}">
        <el-tooltip class="item" effect="dark" content="订单变更" placement="bottom" :hide-after="1800" :open-delay="800">
          <el-button type="primary" icon="el-icon-edit" size="small" @click="updateOrderDetail(R.prop('row', scope))"></el-button>
        </el-tooltip>

        <el-tooltip class="item" effect="dark" content="变更发货通知状态" placement="bottom" :hide-after="1800" :open-delay="800">
          <el-button type="danger" size="small" icon="el-icon-truck" @click="deliveryOrderDetail(scope.row)"></el-button>
        </el-tooltip>

      </template>
    </table-view>

    <productinfo-add-or-update v-if="productInfoVisible" ref="productInfo"></productinfo-add-or-update>
    <client-info-add-or-update v-if="clientInfoVisible" ref="clientInfo"></client-info-add-or-update>
    <productplannotice-add-or-update v-if="productPlanNoticeVisible" ref="productPlanNotice" @refreshDataList="getDataList"></productplannotice-add-or-update>
    <deep-category-add-or-update v-if="deepCategoryInfoVisible" ref="deepCategory" ></deep-category-add-or-update>
    <model-info-add-or-update v-if="modelInfoVisible" ref="modelInfo"></model-info-add-or-update>
    <order-update v-if="orderUpdateVisible" ref="orderInfoUpdate" @refreshDataList="getDataList"></order-update>
    <contract-order-info-add-or-update v-if="contractOrderInfoAddOrUpdateVisible" ref="contractOrderInfo" @refreshDataList="getDataList"></contract-order-info-add-or-update>

    <el-dialog
      title="选择当前订单的状态"
      :visible.sync="dialogVisible"
      width="30%">
      <el-radio-group v-model="status">
        <el-radio :label="-1">预排</el-radio>
        <el-radio :label="0">待配货</el-radio>
        <el-radio :label="1">暂时下线</el-radio>
        <el-radio :label="2">加急</el-radio>
        <el-radio :label="3">正常</el-radio>
        <el-radio :label="4">生产中</el-radio>
        <el-radio :label="5">生产完成</el-radio>
        <el-radio :label="90">客户待确认</el-radio>
        <el-radio :label="99">取消</el-radio>
      </el-radio-group>
      <span slot="footer" class="dialog-footer">
        <el-button @click="dialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="modifyOrderStatus">确 定</el-button>
      </span>
    </el-dialog>

    <el-dialog
      title="选择当前纸箱下单的状态"
      :visible.sync="boxOrderDialogVisible"
      width="30%">
      <el-radio-group v-model="boxOrderStatusRadio">
        <el-radio :label="0">未下单</el-radio>

        <el-radio :label="2">已下单</el-radio>

        <el-radio :label="5">正在加工</el-radio>

        <el-radio :label="10">入库完成</el-radio>

        <el-radio :label="15">改用托盘</el-radio>

        <el-radio :label="20">来料加工</el-radio>
      </el-radio-group>
      <span slot="footer" class="dialog-footer">
        <el-button @click="boxOrderDialogVisible = false">取 消</el-button>
        <el-button type="primary" @click="modifyBoxOrderStatus">确 定</el-button>
      </span>
    </el-dialog>
    <el-dialog
      title="修改损耗数量"
      :visible.sync="orderIssuesNumberVisible"
      width="30%">
      <el-input-number v-model="orderIssuesNumber">
      </el-input-number>
      <span slot="footer" class="dialog-footer">
        <el-button @click="orderIssuesNumberVisible = false">取 消</el-button>
        <el-button type="primary" @click="modifyOrderIssuesNumber">确 定</el-button>
      </span>
    </el-dialog>
    <el-dialog
      title="组长审批"
      :visible.sync="teamLeadApprovalVisible"
      width="30%">
      <label >审批状态： </label>
      <el-radio-group v-model="teamLeadApproval" >
        <el-radio :label="3" border>组长待审核</el-radio>

        <el-radio :label="4" border>组长驳回</el-radio>

        <el-radio :label="5" border>组长通过</el-radio>

      </el-radio-group>
      <br>
      <br>
      <label >审批意见： </label>
      <el-input v-model="teamLeadOpinion" placeholder="请输入组长审核意见">
      </el-input>
      <span slot="footer" class="dialog-footer">
        <el-button @click="teamLeadApprovalVisible = false">取 消</el-button>
        <el-button type="primary" @click="modifyTeamLeadApproval">确 定</el-button>
      </span>

    </el-dialog>
    <el-dialog
      title="批量制定发货通知计划"
      :visible.sync="orderPlanNoticeVisible"
      :fullscreen="true"
      :before-close="handleClose"
    >

      <el-form
        ref="dataForm"
        label-width="120px"
        label-position="left"
        style="margin-left:30px"
      >


        <el-form-item label="发货日期" style="width: 400px">
          <el-date-picker
            v-model="deliveryTime"
            align="right"
            type="date"
            placeholder="选择日期"
            value-format="yyyy-MM-dd HH:mm:ss"
            >
          </el-date-picker>

        </el-form-item>

        <el-form-item label="预计到达时间" style="width: 400px">
          <el-date-picker
            v-model="arriveTime"
            align="right"
            type="date"
            placeholder="选择日期"
            value-format="yyyy-MM-dd HH:mm:ss"
          >
          </el-date-picker>

        </el-form-item>


<!--        <el-form-item-->
<!--          prop="freight"-->
<!--          label="运费"-->
<!--          style="width: 400px"-->
<!--        >-->
<!--          <template slot-scope="scope">-->
<!--            <el-input-number controls-position="right" size="small" :min="0"  v-model="freight"  placeholder="运费"></el-input-number>-->
<!--          </template>-->

<!--        </el-form-item >-->

<!--        <el-form-item-->
<!--          prop="totalWeightInfo"-->
<!--          label="重量"-->
<!--          style="width: 400px"-->
<!--        >-->
<!--          <template slot-scope="scope">-->
<!--            <el-input-number controls-position="right" size="small" :min="0"  v-model="totalWeightInfo"  placeholder="重量"></el-input-number>-->
<!--          </template>-->

<!--        </el-form-item>-->

        <el-form-item
          prop="remark"
          label="备注"
          style="width: 400px"
        >
          <template slot-scope="scope">
            <el-input type="textarea" controls-position="right" size="small" :min="0"  v-model="remark" placeholder="备注"></el-input>
          </template>
        </el-form-item>

      </el-form>

      <el-table
        :data="tableListData"
        border
        style="display: inline-block">
        <el-table-column
          prop="contractNo"
          label="合同编号"
          align="center"
          width="150"
        >
          <template slot-scope="scope">
            <el-input controls-position="right" size="small" readOnly  v-model="scope.row.contractNo" placeholder="合同编号"></el-input>
          </template>
        </el-table-column>
        <el-table-column
          prop="orderNo"
          label="订单编号"
          align="center"
          width="170"
        >
          <template slot-scope="scope">
            <el-input controls-position="right" size="small" readOnly  v-model="scope.row.orderNo" placeholder="订单编号"></el-input>
          </template>
        </el-table-column>

        <el-table-column
          prop="productNo"
          label="产品名称"
          align="center"
          width="150"
        >
          <template slot-scope="scope">
            <el-input controls-position="right" size="small" readOnly  v-model="scope.row.productNo" placeholder="产品名称"></el-input>
          </template>
        </el-table-column>

        <el-table-column
          prop="clientName"
          label="客户名称"
          align="center"
          width="150"
        >
          <template slot-scope="scope">
            <el-input controls-position="right" size="small"  v-model="scope.row.clientName" placeholder="客户名称"></el-input>
          </template>
        </el-table-column>

        <el-table-column
          prop="productWeight"
          label="克重"
          width="130"
          align="center"
        >
          <template slot-scope="scope">
            <el-input-number controls-position="right" size="small" :min="0"  v-model="scope.row.productWeight" placeholder="克重"></el-input-number>
          </template>
        </el-table-column>


        <el-table-column
          prop="orderProductNumber"
          label="订单数量"
          width="150"
          align="center"
        >
          <template slot-scope="scope">
            <el-input-number controls-position="right" size="small" :min="0"  v-model="scope.row.orderProductNumber"  placeholder="数量"></el-input-number>
          </template>
        </el-table-column>

        <el-table-column
          prop="putInStorageNumber"
          label="库存数量"
          width="130"
          align="center"
        >
          <template slot-scope="scope">
            <el-input-number controls-position="right" size="small" :min="0"  v-model="scope.row.putInStorageNumber"  placeholder="库存数量"></el-input-number>
          </template>
        </el-table-column>

          <el-table-column
            prop="leaveStorageNumber"
            label="已发数量"
            width="130"
            align="center"
          >
            <template slot-scope="scope">
              <el-input-number controls-position="right" size="small" :min="0"  v-model="scope.row.leaveStorageNumber"  placeholder="已发数量"></el-input-number>
            </template>
          </el-table-column>

        <el-table-column
          prop="deliveryType"
          label="发货类型"
          align="center"
          width="140"
        >
          <template slot-scope="scope">
            <el-select v-model="scope.row.deliveryType" clearable filterable   placeholder="发货类型">
              <el-option label="按数量"   :value=0>按数量</el-option>
              <el-option label="全发"  :value=1>全发</el-option>
            </el-select>
          </template>
        </el-table-column>

        <el-table-column
          prop="deliveryNumber"
          label="发货数量"
          align="center"
        >
          <template slot-scope="scope">
            <el-input-number size="small" controls-position="right"  v-model="scope.row.deliveryNumber" placeholder="发货数量"></el-input-number>
          </template>
        </el-table-column>


        <el-table-column
          prop="deliveryAddress"
          label="收货地址"
          width="200"
          align="center"
        >
          <template slot-scope="scope">
            <el-input type="textarea" controls-position="right" size="small" :min="0"  v-model="scope.row.deliveryAddress" placeholder="收货地址"></el-input>
          </template>
        </el-table-column>

      </el-table>


      <span slot="footer" class="dialog-footer">
        <el-button @click="orderPlanNoticeVisible = false">取 消</el-button>
        <el-button type="primary" @click="saveConsignNoteInfo">确 定</el-button>
      </span>

    </el-dialog>

    <el-dialog
      title="查看订单审批流转时间线"
      :visible.sync="orderTimeLineVisible"
      :close-on-click-modal="false"
      :close-on-press-escape="true"
      width="40%">
      <div class="block">
        <el-timeline>
          <el-timeline-item
            v-for="(activity, index) in activities"
            :key="index"
            :icon="activity.icon"
            :type="activity.approveType"
            :color="activity.color"
            :size="activity.size"
            :timestamp="activity.timestamp">
            {{activity.content}}
          </el-timeline-item>
        </el-timeline>
      </div>


      <span slot="footer" class="dialog-footer">
        <el-button @click="orderTimeLineVisible = false">取 消</el-button>
        <el-button type="primary" @click="orderTimeLineVisible=false">确 定</el-button>
      </span>
    </el-dialog>
  </div>
</template>

<script>
import AddOrUpdate from './orderdetail-add-or-update'
import OrderUpdate from './orderdetail-update'
import ContractOrderInfoAddOrUpdate from '@/views/modules/contract/contractorderinfo-add-or-update'

import tableView from '@/components/tableView/index'
import basicMixins from '@/utils/commonViewMixins'
import ProductinfoAddOrUpdate from '@/views/modules/product/productinfo-add-or-update'
import ProductplannoticeAddOrUpdate from '@/views/modules/product/productplannotice-add-or-update'
import ClientInfoAddOrUpdate from '@/views/modules/client/clientinfo-add-or-update'
import DeepCategoryAddOrUpdate from '@/views/modules/deep/deepcategory-add-or-update'
import {mRequest} from '@/utils/request'
import {exportHandle, isAuth} from '@/utils'
import ModelInfoAddOrUpdate from '@/views/modules/model/modelinfo-add-or-update'
import treeView from '@/components/treeView'

export default {
  mixins: [basicMixins],
  data() {
    return {
      isAuth: isAuth,
      status: 0,
      bigMouth: '',
      boxOrderStatusRadio: 0,
      orderIssuesNumber: 0,
      dialogVisible: false,
      modelInfoVisible: false,
      orderIssuesNumberVisible: false,
      boxOrderDialogVisible: false,
      productPlanNoticeVisible: false,
      contractOrderInfoAddOrUpdateVisible: false,
      productInfoVisible: false,
      clientInfoVisible: false,
      deepCategoryInfoVisible: false,
      teamLeadApprovalVisible: false,
      orderPlanNoticeVisible: false,
      orderUpdateVisible: false,
      orderTimeLineVisible: false,
      updatePlanOrderStatus: false,
      productDeviceList: [],
      deviceIdList: [],
      orderDetailList: [],
      productInfoList: [],
      modelInfoList: [],
      tableListData: [],
      deepCategoryList: [],
      productDeviceTreeList: [],
      defaultProps: {
        children: 'children',
        label: 'name'
      },
      sysUserList: [],
      deviceId: '',
      onlineTime: '',
      teamLeadApproval:6,
      teamLeadOpinion: '通过',
      sumInfo: {orderProductNumber: 'orderProductNumber',totalPrice:'totalPrice'},
      deliveryTime: '',
      arriveTime: '',
      licencePlateId: '',
      licencePlateList: [],
      taxInclusive: 0,
      freight: '',
      totalWeightInfo: '',
      remark: '',
      searchAttrs: {
        productNo: {
          label: '产品名称',
          placeholder: '请输入产品名称',
        },
        productWeight: {
          label: '产品重量',
          placeholder: '请输入重量'
        },
        clientId: {
          label: '客户名称',
          clearable: true,
          type: 'autoComplete',
          placeholder: '请输入客户名称',
          querySearchApiName: 'clientApi/getClientList'
        },
        dateTimeRange: {
          type: 'date',
          dateType: 'daterange',
          clearable: true
        }
      },
      primaryKey: 'id',
      listApiName: 'orderApi/listOrderDetailByContract',
      deleteApiName: 'orderApi/deleteOrderDetail',
      importApiName: 'orderApi/importOrderDetail',
      exportApiName: 'orderApi/exportOrderDetailInfo',
      deleteAuthName: 'order:orderdetail:delete',
      boxOrderAuthName: 'order:orderdetail:boxOrder',
      teamLeadApprovalAuthName: 'order:orderdetail:teamLeadApproval',
      showAttrs: {
        orderNo: {
          label: '订单子编号',
          width: 150
        },
        /**
         *   {label: 0, text: '待配货'},
         *             {label: 5, text: '未出货'},
         *             {label: 10, text: '已出'},
         *             {label: 15, text: '缺货'},
         */
        clientName: {label: '客户',width: 120},
        status: {
          label: '状态',
          type: 'radio',
          width: 65,
          items: [
            {value: -1, text: '缺货', tagType: 'danger'},
            {value: 0, text: '待配货',tagType: 'info'},
            {value: 15, text: '采购中', tagType: 'warning'},
            {value: 17, text: '采购完成', tagType: 'success'},
            {value: 20, text: '未出货', tagType: 'primary'},
            {value: 50,text: '部分发货', tagType: 'warning'},
            {value: 55,text: '已全出货', tagType: 'success' },
            {value: 66, text: '已签收', tagType: 'success'},
            {value: 90, text: '客户退货', tagType: 'danger'},
            {value: 99, text: '订单取消', tagType: 'danger'},
          ]
        },
        orderTime: {label: '订单时间', type: 'date', width: 100},
        productNo: {
          label: '产品编号',
          width: 120,
          type: 'linkLabel',
          routerName: 'product-product-info-all',
          searchKey: 'productNo'
        },
        // lightGlassPrice: {
        //   label: '光瓶价格',
        //   showAuthName: 'order:unitprice:show'
        // },
        unitPrice: {
          label: '单价',
          showAuthName: 'order:unitprice:show'
        },
        orderProductNumber: {label: '订单数量'},
        totalPrice: {
          label: '总价',
          showAuthName: 'order:unitprice:show'
        },
        productWeight: {label: '克数'},

        remark: {label: '备注', width: 140},

        // bottleCraft: {label: '工艺'},
        salesperson: {label: '销售'},

        contractNo: {
          label: '合同编号',
          width: 150,
          type: 'labelWithStatus',
          statusAttr: 'messageStatus',
          items: [
            {value: 0, text: '未读', tagType: 'danger'}
          ]
        }
      },
      activities: [{
        content: '客户确认订单信息',
        timestamp: '2018-04-12 20:46',
        size: 'large',
        type: 'primary',
        icon: 'el-icon-more'
      },
        {
        content: '组长审核完成',
        timestamp: '2018-04-03 20:46',
        color: '#0bbd87'
      }, {
        content: '纸箱审核完成',
        timestamp: '2018-04-03 20:46',
        size: 'large'
      },
        {
          content: '模具审核完成',
          timestamp: '2018-04-03 20:46',
          size: 'large'
        },
        {
        content: '排单待审核',
        timestamp: '2018-04-03 20:46'
      },
      {
        content: '纸箱生产中',
        timestamp: '2018-04-03 20:46',
        size: 'large'
      },
        {
          content: '纸箱入库中',
          timestamp: '2018-04-03 20:46',
          size: 'large'
        },
        {
          content: '预计上机时间',
          timestamp: '2018-04-03 20:46'
        },
        {
          content: '生产中',
          timestamp: '2018-04-03 20:46'
        },
        {
          content: '成品入库',
          timestamp: '2018-04-03 20:46'
        },
        {
          content: '生成发货通知单',
          timestamp: '2018-04-03 20:46'
        },
        {
          content: '出库中',
          timestamp: '2018-04-03 20:46',
          type: 'success'
        },
        {
          content: '出库完成',
          timestamp: '2018-04-03 20:46',
          color: '#0bbd87'
        }

      ]
    }
  },
  methods: {
    deliveryOrderDetail(order) {
      this.modifyOrder = order
      if (this.modifyOrder.shippingStatus == 1) {
        this.modifyOrder.shippingStatus = 0
      }else {
        this.modifyOrder.shippingStatus = 1
      }
      mRequest('orderApi/updateOrderDetail', this.modifyOrder, () => {
        this.modifyOrder = null
        this.getDataList()
      })
    },
    productDeviceTreeListInit() {
      mRequest('productApi/getProductDeviceListByParent', {}, (res) => {
        this.productDeviceList = this.R.pathOr([], ['data', 'list'], res)
        const productDeviceTreeList = [{
          id: '',
          name: '生产线信息',
          nodeType: 0,
          children: []
        }]

        productDeviceTreeList[0].children = this.productDeviceList
        this.productDeviceTreeList = productDeviceTreeList;
      })
    },
    openOrderStatusDialog(order) {
      this.dialogVisible = true
      this.modifyOrder = order
      const {status} = order

      this.status = status
    },
    modifyOrderStatus() {
      if (this.modifyOrder.status === this.status) {
        return
      }
      this.modifyOrder.status = this.status

      mRequest('orderApi/updateOrderDetail', this.modifyOrder, () => {
        this.modifyOrder = null
        this.status = 0
        this.dialogVisible = false
        this.getDataList()
      })
    },
    modifyTeamLeadApproval() {
      if (this.modifyOrder.teamLeadApproval === this.teamLeadApproval) {
        return
      }
      this.modifyOrder.teamLeadApproval = this.teamLeadApproval
      this.modifyOrder.teamLeadOpinion = this.teamLeadOpinion

      mRequest('orderApi/updateOrderDetail', this.modifyOrder, () => {
        this.modifyOrder = null
        this.teamLeadApproval = 6
        this.teamLeadOpinion = ''
        this.teamLeadApprovalVisible = false
        this.getDataList()
      })
    },
    openTeamLeadApprovalDialog(order) {
      this.teamLeadApprovalVisible = true
      this.modifyOrder = order
      const {teamLeadApproval} = order

      this.teamLeadApproval = teamLeadApproval
    },

    openBoxOrderStatusDialog(order) {
      this.boxOrderDialogVisible = true
      this.modifyOrder = order
      const {boxOrderStatus} = order

      this.boxOrderStatusRadio = boxOrderStatus
    },
    modifyBoxOrderStatus(){
      if (this.modifyOrder.boxOrderStatus === this.boxOrderStatusRadio) {
        return
      }
      this.modifyOrder.boxOrderStatus = this.boxOrderStatusRadio

      mRequest('orderApi/updateOrderDetail', this.modifyOrder, () => {
        this.modifyOrder = null
        this.boxOrderStatusRadio = 0
        this.boxOrderDialogVisible = false
        this.getDataList()
      })
    },
    modifyOrderIssuesNumber() {
      if (this.modifyOrder.orderIssuesNumber === this.orderIssuesNumber) {
        return
      }
      this.modifyOrder.orderIssuesNumber = this.orderIssuesNumber

      mRequest('orderApi/updateOrderDetail', this.modifyOrder, () => {
        this.modifyOrder = null
        this.orderIssuesNumber = 0
        this.orderIssuesNumberVisible = false
        this.getDataList()
      })
    },
    openProductPlanNotice(id) {
      this.productPlanNoticeVisible = true
      this.$nextTick(() => {
        if (!this.R.isNil(this.$refs.productPlanNotice)) {
          this.$refs.productPlanNotice.init(null, {orderDetailId: id}, () => {
            this.$router.push({name: 'product-productplannotice'})
          })
        }
      })
    },
    openProductInfoDialog(cb) {
      this.productInfoVisible = true
      this.$nextTick(() => {
        if (!this.R.isNil(this.$refs.productInfo)) {
          this.$refs.productInfo.init(null, {status: 1}, cb)
        }
      })
    },
    openClientInfoDialog(cb) {
      this.clientInfoVisible = true
      this.$nextTick(() => {
        if (!this.R.isNil(this.$refs.clientInfo)) {
          this.$refs.clientInfo.init(null, {status: 1}, cb)
        }
      })
    },
    openDeepCategoryInfoDialog(cb){
      this.deepCategoryInfoVisible = true
      this.$nextTick(() => {
        if (!this.R.isNil(this.$refs.deepCategory)) {
          this.$refs.deepCategory.init(null, {status: 1}, cb)
        }
      })
    },
    openOrderIssuesNumberDialog(order){
      this.orderIssuesNumberVisible = true
      this.modifyOrder = order
      const {orderIssuesNumber} = order

      this.orderIssuesNumber = orderIssuesNumber
    },
    openOrderTimeLineDialog(order) {
      this.orderTimeLineVisible = true
      mRequest('orderApi/getOrderTimeLineInfoByOrderDetailId',{orderDetailId: order.id},(res)=>{
        this.activities = this.R.pathOr([], ['data', 'list'], res)

      })
    },
    initSysUserInfoList() {
      mRequest('systemApi/listAllUser', {}, (res) => {
        this.sysUserList = this.R.pathOr([], ['data', 'list'], res)
      })
    },

    initProductDeviceListByParent() {
      mRequest('productApi/getProductDeviceListByParent', {}, (res) => {
        this.productDeviceList = this.R.pathOr([], ['data', 'list'], res)
      })
    },
    initOrderDetailList() {
      mRequest('orderApi/getOrderDetailList', {}, (res) => {
        this.orderDetailList = this.R.pathOr([], ['data', 'list'], res)
      })
    },
    initProductInfoList() {
      mRequest('productApi/getProductInfoList', {}, (res) => {
        this.productInfoList = this.R.pathOr([], ['data', 'list'], res)
      })
    },
    initDeepCategoryList(attrName = '') {
      mRequest('deepApi/deepCategoryList', {}, (res) => {
        this.deepCategoryList = this.R.pathOr([], ['data', 'list'], res)
      })
    },
    initModelInfoList(attrName = 'modelInfoId') {
      mRequest('modelApi/getModelInfoList', {}, (res) => {
        this.modelInfoList = this.R.pathOr([], ['data', 'list'], res)
      })
    },
    initLicencePlateInfoList() {
      mRequest('licenceApi/getLicencePlateInfoList', {}, (res) => {
        this.licencePlateList = this.R.pathOr([], ['data', 'list'], res)
      })
    },
    updateOrderDetail(param){
      this.orderUpdateVisible = true

      this.$nextTick(() => {

        if (!this.R.isNil(this.$refs.orderInfoUpdate)) {
          this.$refs.orderInfoUpdate.init(param.id, param,null)
        }
      })
    },
    reorderFunc(rows) {
      console.log(rows)
      this.contractOrderInfoAddOrUpdateVisible=true

      this.$nextTick(() => {
        if (!this.R.isNil(this.$refs.contractOrderInfo)) {
          this.$refs.contractOrderInfo.init(null, {tableListData: rows})
        }
      })
    },
    openOrderDialog(param, cb) {
      this.orderUpdateVisible = true
      this.$nextTick(() => {
        if (!this.R.isNil(this.$refs.orderInfoUpdate)) {
          this.$refs.orderInfoUpdate.init(param.id, param, cb, false)
        }
      })
    },
    adviceNoteFunc(rows) {
      this.onlineTime = ''
      this.tableListData = []

      for (let i = 0; i < rows.length; i++) {
        let _obj = {
          'orderDetailId': this.R.prop('id', rows[i]),
          'contractNo': this.R.prop('contractNo', rows[i]),
          'deliveryType': 0,
          'deliveryNumber': 0,
          orderNo: this.R.prop('orderNo', rows[i]),
          productNo: this.R.prop('productNo', rows[i]),
          clientName: this.R.prop('clientName', rows[i]),
          productWeight: this.R.prop('productWeight', rows[i]),
          unitPrice: this.R.prop('lightGlassPrice', rows[i]),
          orderProductNumber: this.R.prop('orderProductNumber', rows[i]),
          putInStorageNumber: this.R.prop('putInStorageNumber', rows[i]),
          leaveStorageNumber: this.R.prop('leaveStorageNumber', rows[i]),
          weightInfo: this.R.prop('weightInfo', rows[i]),
          deliveryAddress: this.R.prop('deliveryAddress', rows[i]),
          contractOrderId: this.R.prop('contractOrderId', rows[i]),
          productId: this.R.prop('productId', rows[i]),
          clientId: this.R.prop('clientId', rows[i])
        }
        this.tableListData.push(_obj)

      }
      this.orderPlanNoticeVisible = true

    },
    saveConsignNoteInfo() {

      mRequest("consignApi/saveConsignNoteAndDetailList", {
        'deliveryTime': this.deliveryTime,
        'arriveTime': this.arriveTime,
        'licencePlateId': this.licencePlateId,
        'taxInclusive': this.taxInclusive,
        'freight': this.freight,
        'totalWeightInfo': this.totalWeightInfo,
        'remark': this.remark,
        'onlineTime': this.onlineTime,
        'deviceId': this.deviceId,
        'tableListData': this.tableListData
      }, (res => {
        let data = res.data
        if (data && data.code == 0) {

          this.$message({
            message: '操作成功',
            type: 'success',
            duration: 1500,
            onClose: () => {
              this.orderPlanNoticeVisible = false
              this.getDataList()
              this.$emit('refreshDataList')
            }
          })
        } else {
          this.$message.error(data.msg)
        }
      }))
    },
    handleClose(done) {
      this.$confirm('确认关闭？')
        .then(_ => {
          done();
        })
        .catch(_ => {});
    }
  },
  components: {
    ProductplannoticeAddOrUpdate,
    ProductinfoAddOrUpdate,
    ModelInfoAddOrUpdate,
    ClientInfoAddOrUpdate,
    DeepCategoryAddOrUpdate,
    ContractOrderInfoAddOrUpdate,
    OrderUpdate,
    treeView,
    tableView
  }
}
</script>
